<!DOCTYPE group PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<group>

<p>These instructions explain how to compile VLFeat on your own. This
can be useful to customize or contribute to VLFeat, but it is
otherwise not necessary (use the
<a href="%pathto:download;">binary package</a> instead).</p>

<ul>
<li><a href="%pathto:compiling.unix;">Compiling on Unix</a></li>
<li><a href="%pathto:compiling.windows;">Compiling on Windows</a></li>
</ul>

<h1 id="compiling.unix">Compiling on Unix</h1>

<p>Compiling for UNIX-like platforms (e.g. Mac OS X, Linux) uses the
standard GNU toolchain. It is usually sufficient to change to VLFeat
root directory, denoted <code>VLFEATROOT</code> in the following, and
type <code>make</code>:</p>
<pre>
> cd VLFEATROOT
> make
</pre>
<p>The make script attempts to automatically detect the host
architecture and configure itself accordingly. If the architecture is
not detected correctly, it can be specified manually. For instance</p>
<pre>
> make ARCH=glx
</pre>
<p>compiles for GNU/Linux 32-bit. <code>make help</code> can be used
to obtain a list of other useful options.</p>

<p><b>MATLAB support.</b> In order for MATLAB support to be compiled,
the MATLAB <code>mex</code> script must be in the current path. If it
is not, its location must be passed to <code>make</code> as
follows. First, determine MATLAB's root directory by running a MATLAB
session and issuing the <code>matlabroot</code>
command. Let <code>MATLABROOT</code> denote the returned path
(e.g. <code>/Applications/MATLAB_R2009b.app/</code>). The <code>mex</code>
script is usually located in <code>MALTABROOT/bin/mex</code>. Then run
the compilation with the command</p>
<pre>
> make MEX=MATLABROOT/bin/mex
</pre>
<p>VLFeat must be compiled for the architecture used by MATLAB (run
 MATLAB's <code>computer</code> command to obtain this
 information). On Mac OS X it is often necessary to turn on 64-bit
 support explicitly by setting <code>ARCH=maci64</code> as both the 32
 and 64 bit versions are plausible targets on 64-bit machines.</p>

<div class="parbox">
<p><b>Mac OS X 10.6 (Snow Leopard), 64-bit, and MATLAB 2009b.</b>
MATLAB 2009b for Snow Leopard has added 64 bit mex support and a
corresponding extension <code>mexmaci64</code>. VLFeat now supports
compiling for this platform, but the architecture must be specified
manually when compiling, either like:</p>

<pre>
make ARCH=maci64
</pre>

<p>or</p>

<pre>
make ARCH=maci
</pre>

<p>Unfortunately, MATLAB 2009b's <code>mex</code> script has a bug that
must be manually fixed in order for this procedure to work
correctly. It is recommend to make backup of the <code>mex</code>
script before attempting this. Th fix the bug, edit the
<code>MATLABROOT/bin/mex</code> script by cutting the line:</p>

<pre>
get_arch    # Call $MATLAB/bin/util/arch.sh
</pre>

<p>and pasting it after the processing of options:</p>

<pre>
...
shift
done

#PASTE get_arch call here
get_arch    # Call $MATLAB/bin/util/arch.sh

if [ $v7_compat -eq 1 ] ; then
fc_flags="$fc_flags -DMX_COMPAT_32"
...
</pre>
</div>

<h1 id="compiling.windows">Compiling on Windows</h1>

<p>For Windows, the library bundles an NMake makefile
 (<code>Makefile.mak</code>). In order to use it, you must edit
 Makefile.mak to adjust the values of a number of configuration
 variables to match your setup. Once you have done that, start the
 Visual Studio Command Prompt and type <code>nmake /f
 Makefile.mak</code>.</p>

<p>For Windows platform, it is also possible to compile just the
MATLAB MEX files from within MATLAB (using the <code>vl_compile</code>
command). This is meant to help less experienced users that may need
to recompile the mex file due to binary incompatibilities with older
MATLAB versions.</p>

<div class="parbox">
<p><b>MATLAB 7.0 and earlier</b> require recompiling the MEX files by
 the provided <code>vl_compile</code> command.
</p>
</div>

<h3>Windows troubleshooting</h3>

<dl>
 <dt>syntax error: '=' unexpected:</dt>
 <dd><p>Use <code>nmake /f Makefile.mak</code>.
   Without <code>/f</code>, nmake will default to the wrong
   makefile.</p></dd>
 <dt>'long' followed by 'long' is illegal:</dt>
 <dd><p>This error is usually caused by
   attempting to compile outside of the Visual Studio Command Prompt.</p></dd>
</dl>


</group>
